<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <%--多附件上传css--%>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
    <style>
        body{
            background: #fff;
        }
        body.dragging, body.dragging * {
            cursor: move !important;
        }
        .dragged {
            position: absolute;
            opacity: 0.5;
            z-index: 2000;
        }
        #example li.placeholder {
            position: relative;
            /** More li styles **/
        }
        #example li.placeholder:before {
            position: absolute;
            /** Define arrowhead **/
        }
    </style>
</head>
<body>

<form:form col-sm-offset-1mmandName="mainTask" cssClass="form-horizontal" role="form" onsubmit="return false;" enctype="multipart/form-data" id="updateForm" action="/taskMain/createTask/">
    <h3 class="tit text-center">任务详情</h3>
    <div class="form-group">
        <div>
            <label class="col-sm-2 control-label">任务名称:</label>
            <div class="col-sm-9">
                <input class="form-control"  value="${mainTask.mainName}"  readonly>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div>
            <label class="col-sm-2 control-label">任务内容:</label>
            <div class="col-sm-9">
                <textarea rows="4" class="form-control"  placeholder="请输入内容" readonly>${mainTask.content}</textarea>
            </div>
        </div>
    </div>
    <%--<div class="form-group">
        <div>
            <label class="col-sm-2 control-label">任务反馈:</label>
            <div class="col-sm-9">
                <textarea rows="4" class="form-control feedback"  placeholder="请输入内容"></textarea>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="form-group">
            <div>
                <label class="col-sm-1 col-sm-offset-1 control-label">反馈附件:</label>
                    &lt;%&ndash;<div class="col-sm-7 pos-rel">&ndash;%&gt;
                <div class="col-sm-9">
                    <div id="uploader"></div>
                        &lt;%&ndash;<input type="file" class="form-control" id="fileupload">&ndash;%&gt;
                </div>
                    &lt;%&ndash;<div class="col-sm-2">&ndash;%&gt;
                    &lt;%&ndash;<button class="btn btn-info" onclick="uploadFile(this,'file','fileName')">&ndash;%&gt;
                    &lt;%&ndash;<span class="glyphicon glyphicon-open"></span>上传附件&ndash;%&gt;
                    &lt;%&ndash;</button>&ndash;%&gt;
                    &lt;%&ndash;</div>&ndash;%&gt;
                &lt;%&ndash;<input type="hidden" id="recipientId" value="${}">&ndash;%&gt;
            </div>
        </div>
    </div>
    <div class="form-group">
        <div>
            <label class="col-sm-2 control-label">任务评价:</label>
            <div class="col-sm-1">
                <select class="form-control text-center" style="text-align-last: center"></select>
            </div>
        </div>
    </div>--%>
    <div class="form-group">
        <label class="col-sm-2 control-label">承办单位:</label>
        <div class="">
            <ol id='example' class="col-sm-offset-2 col-sm-9 list-group"></ol>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-9">
            <button class="btn-success btn-sm confirm">确定</button>
        </div>
    </div>
    <div id="sysId" class="hidden">${mainTask.sysId}</div>
    <%--当前主任务ID--%>
    <div id="taskMainId" class="hidden"></div>

<%--
    <div id="sepcaiTaskId" class="hidden">${specialTask.sysId}</div>
--%>
</form:form>

<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<script src="<s:url value="/assets/js/Sortable.min.js"></s:url>"></script>
<script src="<s:url value="/assets/js/own.js"></s:url>"></script>

<script type="text/javascript">
    $(function  () {
        $.ajax({
            url:'/appAdmin/scoreLevelList',
            dataType:'json',
            type:'post',
            contentType:'application/json',
            data:'{}',
            success:function (data) {
                data.data.forEach(function (item) {
                    $("select").append("<option value=\""+ item.sysId +"\">"+item.name +"</option>")
                })
            }
        });
        var taskMainId = {taskMainId: $('#sysId').text()};
        $.ajax({
            url:'/taskMain/dubanfeedback/getsontask',
            dataType:'json',
            type:'post',
            contentType:'application/json',
            data:JSON.stringify(taskMainId),
            success:function (data) {
                console.log(data);
                $("#taskMainId").html(data.data[0].taskMainId)
                data.data.forEach(function (item) {
                    $("#example").append(" <li data-rank-id="+item.sysId+ "  class=\"list-group-item\" deptId="+ item.deptId +" ><span class='deptname-js' style=\"font-size: 20px\">"+ item.deptName +" </span>  <span style=\"font-size: 20px\">       -->评价： "+ item.evaluations +" </span> </li>")
                })
            }
        })
    });
    new Sortable(example, {
        animation: 150,
        group: 'shared', // set both lists to same group
        // 元素被选中
        onChoose: function (/**Event*/evt) {
            evt.oldIndex;  // element index within parent
        },

        // 元素未被选中的时候（从选中到未选中）
        onUnchoose: function(/**Event*/evt) {
            // same properties as onEnd
        },

        // 开始拖拽的时候
        onStart: function (/**Event*/evt) {
            evt.oldIndex;  // element index within parent
        },

        // 结束拖拽
        onEnd: function (/**Event*/evt) {
            var itemEl = evt.item;  // dragged HTMLElement
            evt.to;    // target list
            evt.from;  // previous list
            evt.oldIndex;  // element's old index within old parent
            evt.newIndex;  // element's new index within new parent
            evt.clone // the clone element
            evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
        },

        // 元素从一个列表拖拽到另一个列表
        onAdd: function (/**Event*/evt) {
            // same properties as onEnd
        },

        // 列表内元素顺序更新的时候触发
        onUpdate: function (/**Event*/evt) {
            // same properties as onEnd
        },

        // 列表的任何更改都会触发
        onSort: function (/**Event*/evt) {
            // same properties as onEnd
        },

        // 元素从列表中移除进入另一个列表
        onRemove: function (/**Event*/evt) {
            // same properties as onEnd
        },

        // 试图拖拽一个filtered的元素
        onFilter: function (/**Event*/evt) {
            var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
        },

        // 拖拽移动的时候
        onMove: function (/**Event*/evt, /**Event*/originalEvent) {

            evt.dragged; // dragged HTMLElement
            evt.draggedRect; // DOMRect {left, top, right, bottom}
            evt.related; // HTMLElement on which have guided
            evt.relatedRect; // DOMRect
            evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
            originalEvent.clientY; // mouse position
            // console.log(originalEvent,evt)
        },

        // clone一个元素的时候触发
        onClone: function (/**Event*/evt) {

            var origEl = evt.item;
            var cloneEl = evt.clone;
        },

        // 拖拽元素改变位置的时候
        onChange: function(/**Event*/evt) {
            // console.log(evt.newIndex )
        }
    });
    $('.confirm').click(function () {
        var sysId = $('#sysId').text();         //获取sysId值
        var sort = [];                           //承办单位
        $('#example').find('li').each(function() {
            sort.push({
            deptId:$(this).attr('deptId'),sysId:$(this).attr("data-rank-id"),deptName:$(this).children(".deptname-js").text(),deptRank:$(this).index()+1
            })
        });
        var taskMainId =$('#sysId').text();   //主任id
      //  var evaluation = $('select').val();          //好评
      //  var feedback = $('.feedback').val()         //获取反馈内容
      //  var sptaskId = $("#sepcaiTaskId").text();
        var datas = {
            /*specialId:sptaskId,
            mainResult:feedback,                        //反馈内容
            evaMainTask:evaluation,  */                    //好评
            json:JSON.stringify(sort),                         //承办单位
            sysId: taskMainId,                 //主任务ID
           /* mainResultFile: fileStr,                       //附件
            mainResultFileName: fileNameStr */              //附件名
        }
        //提交
       /* $.post("/taskMain/submintDbFeedBack",datas,function (results) {
            if (data.code == 200) {
                alert(data.message);
                setTimeout(function () {
                    //刷新当前页面
                    open(location, '_self').close();
                }, 50)
            } else {
                alert(data.message);
            }
            failure(",FeedbackConfirm", 0)
        })*/

        //提交
        $.ajax({
            url:'/taskMain/rankDepts',
            dataType:'json',
            type:'post',
            contentType:'application/json',
            data:JSON.stringify(datas),
            success:function (data) {
                console.log(data);
                if(data.code ==200){
                    alert("操作成功")
                    setTimeout(function () {
                        //刷新当前页面
                        open(location, '_self').close();
                    }, 50)
                }else {
                    alert("操作失败:"+data.message);
                }
            }
        })
    })


  // [
  //   {"deptId":"","deptName":"政府办","sort":"1"},
  //   {"deptId":"","deptName":"效能办","sort":"2"},
  //   {"deptId":"","deptName":"县政委","sort":"3"},
  //   {"deptId":"","deptName":"作战室","sort":"4"}
  //   ]
</script>
<%--<script>
    &lt;%&ndash;多文件上传&ndash;%&gt;
    var fileStr = "";//id字符串拼接
    var fileNameStr = "";//文件名字符串拼接
    var uploader = easyUploader({
        id: "uploader",
        accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
        action: '/filesUpload/uploadFiles',
        dataFormat: 'formData',
        maxCount: 10,//允许上传的个数
        maxSize: 2000,//允许上传最大的容量
        multiple: true,
        data: null,
        beforeUpload: function (file, data, args) {
        },
        onChange: function (fileList) {
        },
        onRemove: function (removedFiles, files) {
            console.log('onRemove', removedFiles);
        },
        onSuccess: function (res) {
            console.log('onSuccess', res);
            if (res.data !== undefined && res.data[0] !== undefined) {
                //拼接文件id 和 文件名
                fileStr += res.data[0].sysid + ",";
                fileNameStr += res.data[0].oldName + ",";
                console.log(fileStr)
                console.log(fileNameStr)
            }
        },
        onError: function (err) {
            console.log('onError', err);
        },
    });
</script>--%>
</body>
</html>